home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Xconq 7.0d37 / source / kernel / game.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-02  |  9.4 KB  |  361 lines  |  [TEXT/KAHL]

  1. /* Interface between game parameters and the rest of Xconq.
  2.    Copyright (C) 1992, 1993, 1994 Stanley T. Shebs.
  3.  
  4. Xconq is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.  See the file COPYING.  */
  8.  
  9. /* This file defines the structures that are filled in with type info,
  10.    one for each type, plus the declarations for all functions and variables. */
  11.  
  12. /* Numbers guaranteed to be invalid types in each category.  Should be
  13.    careful that these don't overflow anything. */
  14.  
  15. #define NONUTYPE (MAXUTYPES)
  16. #define NONMTYPE (MAXMTYPES)
  17. #define NONTTYPE (MAXTTYPES)
  18.  
  19. /* Indices for each category of types. */
  20.  
  21. typedef enum {
  22.   UTYP = 0,
  23.   MTYP = 1,
  24.   TTYP = 2
  25. } Typetype;
  26.  
  27. /* The four roles for terrain. */
  28.  
  29. enum terrain_subtype {
  30.     cellsubtype = 0,
  31.     bordersubtype = 1,
  32.     connectionsubtype = 2,
  33.     coatingsubtype = 3
  34. };
  35.  
  36. /* If a specialized Xconq is being compiled, use the specialized .h
  37.    instead of the general one.  All of the general game parameter
  38.    machinery should go away and be replaced by either constant
  39.    defaults or precalculated tables/formulas. */
  40.  
  41. #ifdef SPECIAL
  42.  
  43. #include "special.h"
  44.  
  45. #else
  46.  
  47. #include "lisp.h"
  48.  
  49. /* This is the structure representing info about a property
  50.    of a type, such as a unit type's maximum speed. */
  51.  
  52. typedef struct propertydefn {
  53.     char *name;
  54.     int (*intgetter) PROTO ((int));
  55.     char *(*strgetter) PROTO ((int));
  56.     Obj *(*objgetter) PROTO ((int));
  57.     short offset;
  58.     char *doc;
  59.     short dflt;
  60.     char *dfltstr;
  61.     void (*dlftfn) PROTO ((void));
  62.     short lo, hi;
  63. } PropertyDefn;
  64.  
  65. /* This is the structure with info about a table. */
  66.  
  67. typedef struct tabledefn {
  68.     char *name;
  69.     int (*getter) PROTO ((int, int));
  70.     char *doc;
  71.     short **table, *cnst;
  72.     short dflt;
  73.     short lo, hi;
  74.     Typetype index1, index2;
  75. } TableDefn;
  76.  
  77. /* This is the structure with info about a global variable. */
  78.  
  79. typedef struct vardefn {
  80.     char *name;
  81.     int (*intgetter) PROTO ((void));
  82.     char *(*strgetter) PROTO ((void));
  83.     Obj *(*objgetter) PROTO ((void));
  84.     char *doc;
  85.     long dflt;
  86.     char *dfltstr;
  87.     void (*dlftfn) PROTO ((void));
  88.     long lo, hi;
  89. } VarDefn;
  90.  
  91. extern short numutypes;
  92. extern short nummtypes;
  93. extern short numttypes;
  94.  
  95. typedef struct utype {
  96.  
  97. #undef  DEF_UPROP_I
  98. #define DEF_UPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
  99.     short SLOT;
  100. #undef  DEF_UPROP_S
  101. #define DEF_UPROP_S(name,fname,doc,SLOT,dflt)  \
  102.     char *SLOT;
  103. #undef  DEF_UPROP_L
  104. #define DEF_UPROP_L(name,fname,doc,SLOT)  \
  105.     Obj *SLOT;
  106.  
  107. #include "utype.def"
  108.  
  109. } Utype;
  110.  
  111. /* Definition of material types. */
  112.  
  113. typedef struct mtype {
  114.  
  115. #undef  DEF_MPROP_I
  116. #define DEF_MPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
  117.     short SLOT;
  118. #undef  DEF_MPROP_S
  119. #define DEF_MPROP_S(name,fname,doc,SLOT,dflt)  \
  120.     char *SLOT;
  121. #undef  DEF_MPROP_L
  122. #define DEF_MPROP_L(name,fname,doc,SLOT)  \
  123.     Obj *SLOT;
  124.  
  125. #include "mtype.def"
  126.  
  127. } Mtype;
  128.  
  129. /* Definition of terrain types. */
  130.  
  131. typedef struct ttype {
  132.  
  133. #undef  DEF_TPROP_I
  134. #define DEF_TPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
  135.     short SLOT;
  136. #undef  DEF_TPROP_S
  137. #define DEF_TPROP_S(name,fname,doc,SLOT,dflt)  \
  138.     char *SLOT;
  139. #undef  DEF_TPROP_L
  140. #define DEF_TPROP_L(name,fname,doc,SLOT)  \
  141.     Obj *SLOT;
  142.  
  143. #include "ttype.def"
  144.  
  145. } Ttype;
  146.  
  147. /* The global data. */
  148.  
  149. typedef struct a_globals {
  150.  
  151. #undef  DEF_VAR_I
  152. #define DEF_VAR_I(name,fname,setfname,doc,VAR,lo,dflt,hi)  \
  153.     long VAR;
  154. #undef  DEF_VAR_S
  155. #define DEF_VAR_S(name,fname,setfname,doc,VAR,dflt)  \
  156.     char *VAR;
  157. #undef  DEF_VAR_L
  158. #define DEF_VAR_L(name,fname,setfname,doc,VAR,dflt)  \
  159.     Obj *VAR;
  160.  
  161. #include "gvar.def"
  162.  
  163. } Globals;
  164.  
  165. /* Declarations of the functions accessing and setting type properties. */
  166.  
  167. #undef  DEF_UPROP_I
  168. #define DEF_UPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME PROTO ((int u));
  169. #undef  DEF_UPROP_S
  170. #define DEF_UPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME PROTO ((int u));
  171. #undef  DEF_UPROP_L
  172. #define DEF_UPROP_L(name,FNAME,doc,slot)  Obj *FNAME PROTO ((int u));
  173.  
  174. #include "utype.def"
  175.  
  176. #undef  DEF_MPROP_I
  177. #define DEF_MPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME PROTO ((int m));
  178. #undef  DEF_MPROP_S
  179. #define DEF_MPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME PROTO ((int m));
  180. #undef  DEF_MPROP_L
  181. #define DEF_MPROP_L(name,FNAME,doc,slot)  Obj *FNAME PROTO ((int m));
  182.  
  183. #include "mtype.def"
  184.  
  185. #undef  DEF_TPROP_I
  186. #define DEF_TPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME PROTO ((int t));
  187. #undef  DEF_TPROP_S
  188. #define DEF_TPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME PROTO ((int t));
  189. #undef  DEF_TPROP_L
  190. #define DEF_TPROP_L(name,FNAME,doc,slot)  Obj *FNAME PROTO ((int t));
  191.  
  192. #include "ttype.def"
  193.  
  194. #undef  DEF_VAR_I
  195. #define DEF_VAR_I(str,FNAME,SETFNAME,doc,var,lo,dflt,hi)  \
  196.   int FNAME PROTO ((void));  \
  197.   void SETFNAME PROTO ((int val));
  198. #undef  DEF_VAR_S
  199. #define DEF_VAR_S(str,FNAME,SETFNAME,doc,var,dflt)  \
  200.   char *FNAME PROTO ((void));  \
  201.   void SETFNAME PROTO ((char *val));
  202. #undef  DEF_VAR_L
  203. #define DEF_VAR_L(str,FNAME,SETFNAME,doc,var,dflt)  \
  204.   Obj *FNAME PROTO ((void));  \
  205.   void SETFNAME PROTO ((Obj *val));
  206.  
  207. #include "gvar.def"
  208.  
  209. /* Declarations of table accessor functions and the globals
  210.    for constant and filled-in tables. */
  211.  
  212. #undef  DEF_UU_TABLE
  213. #define DEF_UU_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  214.   int FNAME PROTO ((int u1, int u2));  \
  215.   extern short *TABLE, CNST;
  216. #undef  DEF_UM_TABLE
  217. #define DEF_UM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  218.   int FNAME PROTO ((int u, int m));  \
  219.   extern short *TABLE, CNST;
  220. #undef  DEF_UT_TABLE
  221. #define DEF_UT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  222.   int FNAME PROTO ((int u, int t));  \
  223.   extern short *TABLE, CNST;
  224. #undef  DEF_TM_TABLE
  225. #define DEF_TM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  226.   int FNAME PROTO ((int t, int m));  \
  227.   extern short *TABLE, CNST;
  228. #undef  DEF_TT_TABLE
  229. #define DEF_TT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  230.   int FNAME PROTO ((int t1, int t2));  \
  231.   extern short *TABLE, CNST;
  232. #undef  DEF_MM_TABLE
  233. #define DEF_MM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  234.   int FNAME PROTO ((int m1, int m2));  \
  235.   extern short *TABLE, CNST;
  236.  
  237. #include "table.def"
  238.  
  239. /* Declarations of the globals description structures. */
  240.  
  241. extern Globals globals;
  242.  
  243. extern Utype *utypes;
  244.  
  245. extern Mtype *mtypes;
  246.  
  247. extern Ttype *ttypes;
  248.  
  249. extern PropertyDefn utypedefns[];
  250.  
  251. extern PropertyDefn mtypedefns[];
  252.  
  253. extern PropertyDefn ttypedefns[];
  254.  
  255. extern TableDefn tabledefns[];
  256.  
  257. extern VarDefn vardefns[];
  258.  
  259. #endif /* SPECIAL */
  260.  
  261. /* The following definitions are valid for both general and specialized
  262.    games. */
  263.  
  264. /* Macros for iterating over types. */
  265.  
  266. #define for_all_unit_types(v)      for (v = 0; v < numutypes; ++v)
  267.  
  268. #define for_all_material_types(v)  for (v = 0; v < nummtypes; ++v)
  269.  
  270. #define for_all_terrain_types(v)   for (v = 0; v < numttypes; ++v)
  271.  
  272. #define for_all_possible_unit_types(v)      for (v = 0; v < MAXUTYPES; ++v)
  273.  
  274. #define for_all_possible_material_types(v)  for (v = 0; v < MAXMTYPES; ++v)
  275.  
  276. #define for_all_possible_terrain_types(v)   for (v = 0; v < MAXTTYPES; ++v)
  277.  
  278. /* Macros to encapsulate special cases. */
  279.  
  280. #define could_create(u1,u2) (uu_acp_to_create(u1,u2) > 0)
  281.  
  282. #define could_repair(u1, u2) (uu_repair(u1,u2) > 0)
  283.  
  284. /* Fix eventually. */
  285.  
  286. /* (should say u_... or ..._type ?) */
  287.  
  288. #define actor(u) (u_acp(u) > 0)
  289.  
  290. #define mobile(u) (u_speed(u) > 0)
  291.  
  292. /* backward compat */
  293.  
  294. #define could_occupy(u,t) \
  295.   (ut_capacity_x(u,t) > 0 || ut_size(u,t) < t_capacity(t))
  296.  
  297. #define u_hp(u) (u_hp_max(u))
  298.  
  299. /* Macros for units. */
  300.  
  301. #define could_move(u,t) (!ut_vanishes_on(u, t) && !ut_wrecks_on(u, t))
  302.  
  303. #define could_carry(u1,u2)  \
  304.   (uu_capacity_x(u1,u2) > 0 || uu_size(u2,u1) <= u_capacity(u1))
  305.  
  306. #define could_hit(u1,u2) (uu_hit(u1,u2) > 0)
  307.  
  308. #define will_garrison(u1, u2) (uu_hp_to_garrison(u1, u2) > 0)
  309.  
  310. /* These need actual units rather than types. */
  311.  
  312. #define impassable(u, x, y) (!could_move((u)->type, terrain_at((x), (y))))
  313.  
  314. #define isbase(u) (u_is_base((u)->type))
  315.  
  316. #define base_builder(u) (u_is_base_builder((u)->type))
  317.  
  318. #define istransport(u) (u_is_transport((u)->type))
  319.  
  320. #define t_is_cell(t) (t_subtype(t) == cellsubtype)
  321.  
  322. #define t_is_border(t) (t_subtype(t) == bordersubtype)
  323.  
  324. #define t_is_connection(t) (t_subtype(t) == connectionsubtype)
  325.  
  326. #define t_is_coating(t) (t_subtype(t) == coatingsubtype)
  327.  
  328. #define is_unit_type(u) ((u) >= 0 && (u) < numutypes)
  329.  
  330. #define is_material_type(m) ((m) >= 0 && (m) < nummtypes)
  331.  
  332. #define is_terrain_type(t) ((t) >= 0 && (t) < numttypes)
  333.  
  334. extern short tmputype;
  335. extern short tmpmtype;
  336. extern short tmpttype;
  337.  
  338. extern void checku PROTO ((int x));
  339. extern void utype_error  PROTO ((int u));
  340. extern void checkm PROTO ((int x));
  341. extern void mtype_error  PROTO ((int m));
  342. extern void checkt PROTO ((int x));
  343. extern void ttype_error  PROTO ((int t));
  344. extern void init_types PROTO ((void));
  345. extern void init_globals PROTO ((void));
  346. extern void default_unit_type PROTO ((int x));
  347. extern void default_material_type PROTO ((int x));
  348. extern void default_terrain_type PROTO ((int x));
  349. extern char *index_type_name();
  350. extern void allocate_table PROTO ((int tbl, int reset));
  351. extern int numtypes_from_index_type PROTO ((int x));
  352. extern char *index_type_name PROTO ((int x));
  353.  
  354. extern void set_g_synth_methods_default PROTO ((void));
  355. extern void set_g_side_lib_default PROTO ((void));
  356. #if 0 /* unused */
  357. extern Obj *get_u_extension PROTO ((int u, char *name, Obj *dflt));
  358. extern Obj *get_m_extension PROTO ((int m, char *name, Obj *dflt));
  359. extern Obj *get_t_extension PROTO ((int t, char *name, Obj *dflt));
  360. #endif
  361.